﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using Engine.POI;

namespace Engine.FileReaders
{
    class IGOFileReader
    {
        private static char DELIMETER = ',';


        /// <summary>
        /// 
        /// </summary>
        /// <param name="Path"></param>
        /// <returns></returns>
        public IEnumerable<BasePoi> Read(string Path)
        {
            return Read(Path, DELIMETER);
        }


        /// <summary>
        /// 
        /// </summary>
        /// <param name="Path"></param>
        /// <param name="delimeter"></param>
        /// <returns></returns>
        public IEnumerable<BasePoi> Read(string Path, char delimeter)
        {
            if (!System.IO.File.Exists(Path))
                throw new System.IO.FileNotFoundException("File not found", Path);
            string[] lines = File.ReadAllLines(Path);
            List<BasePoi> list = new List<BasePoi>();
            // first line migth contain file description ( skip it )
            float tmp = 0;
            foreach (string line in lines)
            {
                string[] data = line.Split(delimeter);
                if (data.Length > 0)
                {
                    if (!float.TryParse(data[0], out tmp))
                        continue;
                    float x, y;
                    x = float.Parse(data[0]);
                    y = float.Parse(data[1]);
                    CameraType type = (CameraType)int.Parse(data[2]);
                    int speed = int.Parse(data[3]);
                    CameraDirection dir = (CameraDirection)int.Parse(data[4]);
                    int angle = int.Parse(data[5]);

                    CameraPoi poi = new CameraPoi();
                    poi.Location.X = x;
                    poi.Location.Y = y;
                    poi.Type = type;
                    poi.Speed = speed;
                    poi.Direction = dir;
                    poi.Angle = angle;
                    list.Add(poi);

                }
            }
            return list.ToArray();
        }        
    }
}
